/*
 * 
 * v1.2 by tonydon
 */
//package cn.txdnet.test;


import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 *
 * @author txdnet
 */
public class Demo{

    public static void main(String... args)throws Exception{
          test1();
          System.out.println("... sleep 3sec.");
          TimeUnit.SECONDS.sleep(3);
          test2();
          System.out.println("... sleep 5sec.");
          TimeUnit.SECONDS.sleep(5);
          test3();
          System.out.println("... sleep 5sec.");
          TimeUnit.SECONDS.sleep(5);
          test4();
          System.out.println("... sleep 5sec.");
          TimeUnit.SECONDS.sleep(5);
          test5();
		   System.out.println("... sleep 5sec.");
          TimeUnit.SECONDS.sleep(5);
		  test6();
        
    }
    
    
    public static void test1(){
          List<Integer> listA = new ArrayList<Integer>();
        int n = 10000;
        long t1 = System.currentTimeMillis();
        for(int k =0 ; k<n; k++){
            listA.add(k);
            listA.add(k+1);
            listA.add(k+2);
            listA.add(k+3);
            listA.add(k+4);
            listA.add(k+5);
            listA.remove(k+1);
            listA.add(k+6);
        }
        
        long t2 = System.currentTimeMillis();
        
        System.out.println("ArrayList  Add-Remove Test: "+(t2-t1)+" ms, size="+ listA.size()); 

		for(int j=0; j<n ;j++){
			listA.get(j);
		}

		long t3 = System.currentTimeMillis();

		System.out.println("ArrayList  Get Test: "+(t3-t2)+" ms"); 
    }
    
        public static void test2(){
       List<Integer> listA = new LinkedList<Integer>();
        int n = 10000;
        long t1 = System.currentTimeMillis();
        for(int k =0 ; k<n; k++){
            listA.add(k);
            listA.add(k+1);
            listA.add(k+2);
            listA.add(k+3);
            listA.add(k+4);
            listA.add(k+5);
            listA.remove(k+1);
            listA.add(k+6);
        }
        
        long t2 = System.currentTimeMillis();
        
        System.out.println("LinkedList Add-Remove Test: "+(t2-t1)+" ms, size="+ listA.size()); 

		for(int j=0; j<n ;j++){
			listA.get(j);
		}

		long t3 = System.currentTimeMillis();

		System.out.println("LinkedList  Get Test: "+(t3-t2)+" ms"); 
    }

        
       public static void test3(){
          List<Integer> listA = new ArrayList<Integer>();
        int n = 1000000;
        long t1 = System.currentTimeMillis();
        for(int k =0 ; k<n; k++){
            listA.add(k);
        }
        
        long t2 = System.currentTimeMillis();
        
        System.out.println("InitialCapacity=10, ArrayList  Add Test: "+(t2-t1)+" ms, size="+ listA.size()); 

		for(int j=0; j<n ;j++){
			listA.get(j);
		}

		long t3 = System.currentTimeMillis();

		System.out.println("ArrayList  Get Test: "+(t3-t2)+" ms"); 
    }
       
       public static void test4(){
          List<Integer> listA = new ArrayList<Integer>(128);
        int n = 1000000;
        long t1 = System.currentTimeMillis();
        for(int k =0 ; k<n; k++){
            listA.add(k);
        }
        
        long t2 = System.currentTimeMillis();
        
        System.out.println("InitialCapacity=128, ArrayList  Add Test: "+(t2-t1)+" ms, size="+ listA.size()); 

		for(int j=0; j<n ;j++){
			listA.get(j);
		}

		long t3 = System.currentTimeMillis();

		System.out.println("ArrayList  Get Test: "+(t3-t2)+" ms"); 
    }
       
       
            public static void test5(){
          List<Integer> listA = new ArrayList<Integer>(512);
        int n = 1000000;
        long t1 = System.currentTimeMillis();
        for(int k =0 ; k<n; k++){
            listA.add(k);
        }
        
        long t2 = System.currentTimeMillis();
        
        System.out.println("InitialCapacity=512, ArrayList  Add Test: "+(t2-t1)+" ms, size="+ listA.size()); 

		for(int j=0; j<n ;j++){
			listA.get(j);
		}

		long t3 = System.currentTimeMillis();

		System.out.println("ArrayList  Get Test: "+(t3-t2)+" ms"); 
    }
    


	            public static void test6(){
          List<Integer> listA = new ArrayList<Integer>(1024);
        int n = 1000000;
        long t1 = System.currentTimeMillis();
        for(int k =0 ; k<n; k++){
            listA.add(k);
        }
        
        long t2 = System.currentTimeMillis();
        
        System.out.println("InitialCapacity=1024, ArrayList  Add Test: "+(t2-t1)+" ms, size="+ listA.size()); 

		for(int j=0; j<n ;j++){
			listA.get(j);
		}

		long t3 = System.currentTimeMillis();

		System.out.println("ArrayList  Get Test: "+(t3-t2)+" ms"); 
    }
    
}
